//
//  MineCashViewController.m
//  MJApp
//
//  Created by wangliang on 15/3/28.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "MineCashViewController.h"
#import "MineCashPayViewController.h"
#import "MineCashNoAlipayViewController.h"

@interface MineCashViewController ()
@property (weak, nonatomic) IBOutlet UIView *infoView;
@property(nonatomic,strong) NSDictionary *infoDic;//获取到的数据
@property(nonatomic,strong) NSDictionary *lastDic;//传入的数据

@property (weak, nonatomic) IBOutlet UILabel *momeyLabel;
@property (weak, nonatomic) IBOutlet UILabel *integrateLabel;

@end

@implementation MineCashViewController

- (instancetype)initWithDic:(NSDictionary *)lastDic {
    
    if (self = [super init]) {
        
        self.lastDic = lastDic;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self obationData];
    [self UI];
}

- (void)UI {
    
    [((TabBarController *)self.tabBarController) setTabbarHidden:YES];
    self.title = @"我的钱包";
    self.infoView.alpha = 0;
    self.infoView.transform = CGAffineTransformMakeScale(0, 0);
    self.infoView.layer.cornerRadius = 10;
}

- (void)obationData {
    
    NSDictionary *dic = @{@"user_id":[userInfoTool share].ID};
    [WLHttpRequestAfter userGetMyWalletWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        if ([resultDictionary[@"status"] integerValue] == 1) {
            
            self.infoDic = resultDictionary[@"data"];
            [self refreshView];
        }
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}


- (void)refreshView {
    
    self.momeyLabel.text = self.infoDic[@"money"];
    self.integrateLabel.text = self.infoDic[@"integrate"];
}

- (IBAction)infoAction:(id)sender {
    
    [UIView animateWithDuration:0.2 animations:^{
       
        self.infoView.alpha = 1;
        self.infoView.transform = CGAffineTransformMakeScale(1, 1);
    }];
}
- (IBAction)close:(id)sender {
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.infoView.alpha = 0;
        self.infoView.transform = CGAffineTransformMakeScale(0, 0);
    }];
}

- (IBAction)pushInto:(id)sender {
    
    
    if ([self.lastDic[@"user"][@"alipay"] isEqual:@""]) {
        
        [self.navigationController pushViewController:[[MineCashNoAlipayViewController alloc] init] animated:YES];
    }else {
        
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:self.lastDic];
        dic[@"idStr"] = @"余额转入";
        //余额转入
        [self.navigationController pushViewController:[[MineCashPayViewController alloc] initWithDic:dic] animated:YES];
    }

}

- (IBAction)pushOut:(id)sender {
    
    
    if ([self.lastDic[@"user"][@"alipay"] isEqual:@""]) {
        
        [self.navigationController pushViewController:[[MineCashNoAlipayViewController alloc] init] animated:YES];
    }else {
        
        //余额提现
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:self.lastDic];
        dic[@"idStr"] = @"申请提现";
        [self.navigationController pushViewController:[[MineCashPayViewController alloc] initWithDic:dic] animated:YES];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
